<template>
  <view class="container">
    <view class="content-wrapper">
      <view class="header">
        <view class="title">消息</view>
        <view class="menu-icon" @click="openMenu">
          <text class="icon-menu">☰</text>
        </view>
      </view>

      <view class="search-bar">
        <view class="search-icon">🔍</view>
        <input type="text" placeholder="请搜索你要查询的用户聊天" class="search-input" />
      </view>

      <view class="tab-container">
        <view :class="['tab-item', { active: activeTab === 'active' }]" @click="switchTab('active')">未读消息</view>
        <view :class="['tab-item', { active: activeTab === 'archived' }]" @click="switchTab('archived')">已读消息</view>
      </view>

      <scroll-view class="conversation-list" scroll-y>
        <view v-for="(item, index) in filteredConversations" :key="index" class="conversation-item" @click="gotoChat">
          <view class="avatar-container" >
            <image :src="item.avatar" class="avatar" mode="aspectFill"></image>
            <view v-if="item.unread" class="unread-dot"></view>
          </view>
          <view class="info-container">
				<view class="info-top">
					<view class="name">{{ item.name }}</view>
					<view class="role">{{ item.role }}</view>
				</view>
            <view class="message">{{ item.message }}</view>
          </view>
          <view class="time">{{ item.time }}</view>
        </view>
      </scroll-view>
    </view>
	
	<view class="bottom-nav">
	  <navigator url="/pages/volunteerInterface/service" class="nav-item active">
	    <image src="/static/images/regularUser/home-s.png" class="nav-icon"></image>
	    <text>服务</text>
	  </navigator>
	  <navigator url="/pages/volunteerInterface/process" class="nav-item active">
	    <image src="/static/images/regularUser/home-s.png" class="nav-icon"></image>
	    <text>进程</text>
	  </navigator>
	  <navigator url="/pages/volunteerInterface/messages" class="nav-item active">
	    <image src="/static/images/regularUser/home-s.png" class="nav-icon"></image>
	    <text>消息</text>
	  </navigator>
	  <navigator url="/pages/volunteerInterface/me" class="nav-item active">
	    <image src="/static/images/regularUser/my.png" class="nav-icon"></image>
	    <text>我的</text>
	  </navigator>
	</view>
  </view>
</template>
<script>
export default {
  data() {
    return {
      activeTab: 'active', 
      conversations: [
        {
          avatar: '/static/images/select/volunteer.png',
          name: '张一元',
          role: '志愿者',
          message: '已经完成帮助任务请核查...',
          time: '06-03',
          unread: false
        },
        {
          avatar: '/static/images/select/volunteer.png',
          name: '张一',
          role: '志愿者',
          message: '已经完成帮助任务请核查...',
          time: '11-13',
          unread: true
        },
        {
          avatar: '/static/images/select/volunteer.png',
          name: '张三',
          role: '用户',
          message: 'XXXXXX...',
          time: '11-12',
          unread: true
        },
        {
          avatar: '/static/images/select/volunteer.png',
          name: '李四',
          role: '用户',
          message: '已读测试消息',
          time: '11-10',
          unread: false
        }
      ]
    };
  },
  computed: {
    filteredConversations() {
      if (this.activeTab === 'active') {
        return this.conversations.filter(item => item.unread);
      } else {
        return this.conversations.filter(item => !item.unread);
      }
    }
  },
  methods: {
    switchTab(tab) {
      console.log("Switching to tab:", tab);
      this.activeTab = tab;
    },
    openMenu() {
      console.log('Open menu');
    },
	gotoChat(){
		
		uni.navigateTo({
			url:"/pages/regularUser/goto/my/mygoto/goToChat/goToChat"
		})
	}
  }
};
</script>

<style scoped>
.container {
  width: 100%;
  height: 100vh;
  overflow: hidden;
  background: linear-gradient(135deg, #FFF8F2 0%, #FFF0E6 100%);
  background-image: url(/static/images/bg3.jpg);
}


.content-wrapper {
  background-color: rgba(255, 255, 255, 0.9);
  border-radius: 20px;
  margin: 20rpx;
  padding: 20rpx;
  box-shadow: 0 8rpx 20rpx rgba(0, 0, 0, 0.1);
  height: calc(100vh - 40rpx);
  overflow: hidden;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30rpx;
  padding-top: 20px;
}

.title {
	font-size: 36rpx;
	font-weight: bold;
	color: #333;
}

.menu-icon {
  font-size: 40rpx;
  color: #666;
}

.search-bar {
  display: flex;
  align-items: center;
  background-color: #f5f5f5;
  border-radius: 20rpx;
  padding: 25rpx 20rpx;
  margin-bottom: 20rpx;
}

.search-icon {
  margin-right: 10rpx;
  color: #999;
}

.search-input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 23rpx;
  color: #333;
  background: transparent;
}

.tab-container {
  display: flex;
  gap: 30rpx;
  margin-bottom: 30rpx;
}

.tab-item {
  font-size: 28rpx;
  color: #666;
  padding: 10rpx 20rpx;
  border-radius: 15rpx;
  transition: all 0.3s;
}

.tab-item.active {
  color: #FF9F62;
  font-weight: bold;
}

.conversation-list {
  padding:50 20px;
}

.conversation-item {
  display: flex;
  align-items: center;
  padding: 20rpx 0;
  border-bottom: 1rpx solid #eee;
}

.avatar-container {
  position: relative;
  width: 60rpx;
  height: 60rpx;
  border-radius: 50%;
  overflow: hidden;
  margin-right: 20rpx;
}

.avatar {
  width: 60rpx;
  height: 60rpx;
  border-radius: 50%;
}
.info-top{
	display: flex;
}


.info-container {
  flex: 1;
  padding: 10px;
}

.name {
  font-size: 30rpx;
  color: #333;
  font-weight: 500;
}

.role {
  font-size: 22rpx;
  color: #FF9F62;
  margin-top: 4rpx;
  margin-left: 20px;
}

.message {
  font-size: 23rpx;
  color: #666;
  margin-top: 4rpx;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 300rpx;
}

.time {
  font-size: 24rpx;
  color: #999;
  margin-left: auto;
}

/* 底部导航样式*/
.bottom-nav {
	display: flex;
	justify-content: space-around;
	align-items: center;
	height: 80px;
	background-color: white;
	position: fixed;
	bottom: 0;
	width: 100%;
	color: black;
	padding: 0 20px;
}

.nav-item {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	font-size: 14px;
}

.nav-item.active {
	color: #f57f17;
}

.nav-icon {
	width: 24px;
	height: 24px;
	margin-bottom: 5px;
}
</style>